package com.jy.adscm.operation.base.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jy.adscm.operation.base.bean.DmSzmc;
import com.jy.adscm.operation.base.service.DmSzmcService;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2019-01-08
 */
@RestController
@RequestMapping("/adscm/operation/dmSzmc")
public class DmSzmcController {

    @Autowired
    DmSzmcService dmSzmcService;
    @RequestMapping("/insert")
    public SimpleCoreResponse insert(   DmSzmc dms,String data){
        JSONObject jsonObject = JSON.parseObject(data);
       dms.setCode(jsonObject.getString("code"));
       dms.setName(jsonObject.getString("name"));
       dms.setSzlx(jsonObject.getString("szlx"));
       dms.setObject(jsonObject.getString("object"));
        return new SimpleCoreResponse("200","新增成功",dmSzmcService.insert(dms));
    }

    @RequestMapping("update")
    public SimpleCoreResponse update(DmSzmc dm,String data){
        JSONObject jsonObject = JSON.parseObject(data);
        dm.setCode(jsonObject.getString("code"));
        dm.setName(jsonObject.getString("name"));
        if ("收入".equals(jsonObject.getString("szlx"))){
            dm.setSzlx("1");
        }else {
            dm.setSzlx("2");
        }

        dm.setObject(jsonObject.getString("object"));

        return  new SimpleCoreResponse("200","修改成功",dmSzmcService.updateById(dm));
    }

    @RequestMapping("delete")
    public  SimpleCoreResponse delete(DmSzmc dm){
        return new SimpleCoreResponse("200","删除成功",dmSzmcService.deleteById(dm));
    }

    @RequestMapping("queryAll")
    public  SimpleCoreResponse queryAll(){
        return new SimpleCoreResponse("200","查询成功",dmSzmcService.queryAll());
    }
}

